

package com.c2soft.ncmxBtrade.controller;

import javax.servlet.http.HttpServletRequest;

import lombok.extern.log4j.Log4j2;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;


import com.c2soft.ncmxBtrade.command.BrokeOrderCommand;


@Log4j2
@Controller
@RequestMapping("/broke")
public class BrokeOrderMgmtController {
	
	
	@Value("#{systemProperties['ncmxServer.redirect.url']}")
	private String baseServerUrl;
	
	@Autowired
	private RestTemplate restTemplate;
	
	@RequestMapping(value = "/buyOrder", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json")
	@ResponseBody
	public void buy(@RequestBody BrokeOrderCommand buy,HttpServletRequest req) {
		String redirectUrl = baseServerUrl+"order/Brokebuy";
		System.out.println("redirecting buy order to redirectUrl="+redirectUrl);
		//log.info("redirecting buy order to redirectUrl="+redirectUrl);
		buy.setBrokeId((String) req.getSession().getAttribute("trdUsrId"));
		System.out.println(buy);
		//log.info(buy);
		restTemplate.postForObject(redirectUrl, buy, BrokeOrderCommand.class);
		
	}

}
